package com.nulldev.util.java.scripting.nscript.jengine;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;

public class nScriptEngineFactory implements ScriptEngineFactory {

	public static final nScriptEngineFactory INSTANCE = new nScriptEngineFactory();
	
	@Override
	public String getEngineName() {
		return "nScript";
	}

	@Override
	public String getEngineVersion() {
		return "1.0";
	}

	@Override
	public List<String> getExtensions() {
		return Arrays.asList("nscript", "ns", "nullscript");
	}

	@Override
	public List<String> getMimeTypes() {
		return Arrays.asList("text/*", "text/nullscript");
	}

	@Override
	public List<String> getNames() {
		return Collections.singletonList("ns");
	}

	@Override
	public String getLanguageName() {
		return "nScript";
	}

	@Override
	public String getLanguageVersion() {
		return "v1.0";
	}

	@Override
	public Object getParameter(String key) {
		switch(key) {
        	case ScriptEngine.ENGINE: return getEngineName();
        	case ScriptEngine.ENGINE_VERSION: return getEngineVersion();
        	case ScriptEngine.LANGUAGE: return getLanguageName();
        	case ScriptEngine.LANGUAGE_VERSION: return getLanguageVersion();
        	case ScriptEngine.NAME: return getNames().get(0);
        	case "THREADING": return "STATELESS";
        	default: return null;
		}
	}

	@Override
	public String getMethodCallSyntax(String obj, String m, String... args) {
		return "";
	}

	@Override
	public String getOutputStatement(String toDisplay) {
		return "";
	}

	@Override
	public String getProgram(String... statements) {
		return String.join("", statements);
	}

	@Override
	public ScriptEngine getScriptEngine() {
		return new nScriptEngine();
	}

}
